<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Home extends BaseController {
	
	var $num_elements = 10;
	
	function Home(){
		parent::BaseController();		
		
		$this->load->model("Node_Model", "Nodes");
		$this->load->library('pagination');
		
		$this->template->setTheme("web");
		
	}
	
	function index(){
		$pag = $this->pagination->segment_value();
		
		if($pag == NULL){
			$pag = 0;			
		}
		
		$params = array(
			"status" 		=> "publish",
			"num_comments"	=> TRUE,
			"order"			=> array(
				"publish" => "desc"
			)
		);
		
		if(isset($_GET['type'])){
			$params['type'] = $_GET['type'];
		}
		
		if(isset($_GET['cat'])){
			$params['categories'] = array();
			array_push($params['categories'], $_GET['cat']);
		}
		
		if(isset($_GET['tag'])){
			$params['tags'] = array();
			array_push($params['tags'], $_GET['tag']);
		}
		
		if(isset($_GET['status'])){
			$params['status'] = $_GET['status'];
			$this->_addData("filter_status", $_GET['status']);
		}
		
		$params['start'] = $pag;
		$params['offset'] = $this->num_elements;
		
		$num_nodes = $this->mp_cache->model("Nodes", "getCount", array($params));
		$nodes = $this->mp_cache->model("Nodes", "get", array($params));
		
		$this->template->addData("num_nodes", $num_nodes);
		$this->template->addData("nodes", $nodes);
		
		$this->template->render();
	}
}
?>